#Region "Using Directives"
Imports System
Imports System.Collections.Generic
Imports System.Text
#End Region

Namespace C4F.DevKit.Bluetooth

    Namespace ServiceAndDeviceDiscovery


        ''' <summary>
        ''' A generic exception which will be raised when a 
        ''' windows socket error has occurred.
        ''' </summary>
        <Serializable()> _
        Public Class WinsockException
            Inherits Exception

#Region "Private Member"
            ''' <summary>
            ''' Encapsulates the windows error.
            ''' </summary>
            Private winsockErrorObject As WinsockError
#End Region

#Region "Public Property"

            ''' <summary>
            ''' Gets the error.
            ''' </summary>
            Public ReadOnly Property [Error]() As WinsockError

                Get
                    Return winsockErrorObject
                End Get

            End Property

#End Region

#Region "Constructor"

            ''' <summary>
            ''' Initializes the Message property of the new instance to a 
            ''' system-supplied message.
            ''' </summary>
            ''' <param name="winsockError">Represents the winsock error instance.</param>
            Public Sub New(ByVal winsockError As WinsockError)
                MyBase.New()
                winsockErrorObject = winsockError
            End Sub

            ''' <summary>
            ''' Initializes an object of this class and sets the Message property 
            ''' to the specified error message.
            ''' </summary>
            ''' <param name="winsockError">Winsock error instance.</param>
            ''' <param name="message">The message that describes the error.
            ''' </param>
            Public Sub New(ByVal winsockError As WinsockError, ByVal message As String)
                MyBase.New(message)
                winsockErrorObject = winsockError
            End Sub

            ''' <summary>
            ''' Initializes a new instance of the Exception class with a 
            ''' specified error message and a reference 
            ''' to the inner exception that is the cause of this exception.
            ''' </summary>
            ''' <param name="winsockError">Winsock error instance.</param>
            ''' <param name="message">he message that describes the error.
            ''' </param>
            ''' <param name="innerException">The exception that is the cause of
            ''' this exception.</param>
            Public Sub New(ByVal winsockError As WinsockError, ByVal message As String, _
                                                    ByVal innerException As Exception)

                MyBase.New(message, innerException)
                winsockErrorObject = winsockError
            End Sub

            ''' <summary>
            ''' Initializes a new instance of this class with serialized data.             
            ''' </summary>
            ''' <param name="info">The SerializationInfo that holds the serialized
            ''' object data about the exception being thrown.</param>
            ''' <param name="context">The StreamingContext that contains contextual
            ''' information about the source or destination.</param>
            Public Sub New(ByVal info As System.Runtime.Serialization.SerializationInfo, _
                                                        ByVal context As System.Runtime. _
                                                         Serialization.StreamingContext)

                MyBase.New(info, context)
                If info IsNot Nothing Then
                    winsockErrorObject = CType(info.GetValue(BluetoothHelperMessages. _
                                                             GetObjectDataFieldError _
                                                             , GetType(WinsockError)),  _
                                                             WinsockError)
                End If

            End Sub

            ''' <summary>
            ''' Overrides the GetObjectData method of the base class Exception
            ''' </summary>
            ''' <param name="info">The SerializationInfo that holds the serialized
            ''' object data about the exception being thrown.</param>
            ''' <param name="context">The StreamingContext that contains contextual
            ''' information about the source or destination.</param>
#End Region

#Region "Public Function"

            Public Overloads Overrides Sub GetObjectData(ByVal info As System.Runtime. _
                                                         Serialization.SerializationInfo, _
                                                         ByVal context As System.Runtime. _
                                                          Serialization.StreamingContext)

                MyBase.GetObjectData(info, context)

                If info IsNot Nothing Then
                    info.AddValue(BluetoothHelperMessages.GetObjectDataFieldError, Me.Error)
                End If

            End Sub

#End Region

        End Class

    End Namespace

End Namespace
